package com.eostoken.eos_wallet.db.greendao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.eostoken.eos_wallet.db.StringConverter;
import java.util.List;

import com.eostoken.eos_wallet.db.MgpWallet;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "MGP_WALLET".
*/
public class MgpWalletDao extends AbstractDao<MgpWallet, Long> {

    public static final String TABLENAME = "MGP_WALLET";

    /**
     * Properties of entity MgpWallet.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property AccountNameList = new Property(1, String.class, "accountNameList", false, "ACCOUNT_NAME_LIST");
        public final static Property WalletPassword = new Property(2, String.class, "walletPassword", false, "WALLET_PASSWORD");
        public final static Property CurrentAccountName = new Property(3, String.class, "currentAccountName", false, "CURRENT_ACCOUNT_NAME");
        public final static Property PrivateKey = new Property(4, String.class, "privateKey", false, "PRIVATE_KEY");
        public final static Property PublicKey = new Property(5, String.class, "publicKey", false, "PUBLIC_KEY");
        public final static Property Locked = new Property(6, boolean.class, "locked", false, "LOCKED");
        public final static Property WalletName = new Property(7, String.class, "walletName", false, "WALLET_NAME");
        public final static Property MnemonicCode = new Property(8, String.class, "mnemonicCode", false, "MNEMONIC_CODE");
        public final static Property Hint = new Property(9, String.class, "hint", false, "HINT");
    }

    private final StringConverter accountNameListConverter = new StringConverter();
    private final StringConverter mnemonicCodeConverter = new StringConverter();

    public MgpWalletDao(DaoConfig config) {
        super(config);
    }
    
    public MgpWalletDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"MGP_WALLET\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"ACCOUNT_NAME_LIST\" TEXT," + // 1: accountNameList
                "\"WALLET_PASSWORD\" TEXT NOT NULL ," + // 2: walletPassword
                "\"CURRENT_ACCOUNT_NAME\" TEXT UNIQUE ," + // 3: currentAccountName
                "\"PRIVATE_KEY\" TEXT NOT NULL ," + // 4: privateKey
                "\"PUBLIC_KEY\" TEXT," + // 5: publicKey
                "\"LOCKED\" INTEGER NOT NULL ," + // 6: locked
                "\"WALLET_NAME\" TEXT," + // 7: walletName
                "\"MNEMONIC_CODE\" TEXT," + // 8: mnemonicCode
                "\"HINT\" TEXT);"); // 9: hint
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"MGP_WALLET\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, MgpWallet entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        List accountNameList = entity.getAccountNameList();
        if (accountNameList != null) {
            stmt.bindString(2, accountNameListConverter.convertToDatabaseValue(accountNameList));
        }
        stmt.bindString(3, entity.getWalletPassword());
 
        String currentAccountName = entity.getCurrentAccountName();
        if (currentAccountName != null) {
            stmt.bindString(4, currentAccountName);
        }
        stmt.bindString(5, entity.getPrivateKey());
 
        String publicKey = entity.getPublicKey();
        if (publicKey != null) {
            stmt.bindString(6, publicKey);
        }
        stmt.bindLong(7, entity.getLocked() ? 1L: 0L);
 
        String walletName = entity.getWalletName();
        if (walletName != null) {
            stmt.bindString(8, walletName);
        }
 
        List mnemonicCode = entity.getMnemonicCode();
        if (mnemonicCode != null) {
            stmt.bindString(9, mnemonicCodeConverter.convertToDatabaseValue(mnemonicCode));
        }
 
        String hint = entity.getHint();
        if (hint != null) {
            stmt.bindString(10, hint);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, MgpWallet entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        List accountNameList = entity.getAccountNameList();
        if (accountNameList != null) {
            stmt.bindString(2, accountNameListConverter.convertToDatabaseValue(accountNameList));
        }
        stmt.bindString(3, entity.getWalletPassword());
 
        String currentAccountName = entity.getCurrentAccountName();
        if (currentAccountName != null) {
            stmt.bindString(4, currentAccountName);
        }
        stmt.bindString(5, entity.getPrivateKey());
 
        String publicKey = entity.getPublicKey();
        if (publicKey != null) {
            stmt.bindString(6, publicKey);
        }
        stmt.bindLong(7, entity.getLocked() ? 1L: 0L);
 
        String walletName = entity.getWalletName();
        if (walletName != null) {
            stmt.bindString(8, walletName);
        }
 
        List mnemonicCode = entity.getMnemonicCode();
        if (mnemonicCode != null) {
            stmt.bindString(9, mnemonicCodeConverter.convertToDatabaseValue(mnemonicCode));
        }
 
        String hint = entity.getHint();
        if (hint != null) {
            stmt.bindString(10, hint);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public MgpWallet readEntity(Cursor cursor, int offset) {
        MgpWallet entity = new MgpWallet( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : accountNameListConverter.convertToEntityProperty(cursor.getString(offset + 1)), // accountNameList
            cursor.getString(offset + 2), // walletPassword
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // currentAccountName
            cursor.getString(offset + 4), // privateKey
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // publicKey
            cursor.getShort(offset + 6) != 0, // locked
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // walletName
            cursor.isNull(offset + 8) ? null : mnemonicCodeConverter.convertToEntityProperty(cursor.getString(offset + 8)), // mnemonicCode
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // hint
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, MgpWallet entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setAccountNameList(cursor.isNull(offset + 1) ? null : accountNameListConverter.convertToEntityProperty(cursor.getString(offset + 1)));
        entity.setWalletPassword(cursor.getString(offset + 2));
        entity.setCurrentAccountName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPrivateKey(cursor.getString(offset + 4));
        entity.setPublicKey(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setLocked(cursor.getShort(offset + 6) != 0);
        entity.setWalletName(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setMnemonicCode(cursor.isNull(offset + 8) ? null : mnemonicCodeConverter.convertToEntityProperty(cursor.getString(offset + 8)));
        entity.setHint(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(MgpWallet entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(MgpWallet entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(MgpWallet entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
